unit datamUnit;

interface

uses
  SysUtils, Classes, dxSkinsCore, dxSkinDevExpressStyle, Dialogs, frxClass,
  frxDesgn, UniProvider, SQLiteUniProvider, cxLocalization, cxLookAndFeels,
  dxSkinsForm, DBAccess, Uni, DB, DBTables, ImgList, Controls, cxGraphics,forms,
  dxSkinsDefaultPainters, cxStyles, cxClasses, DAScript, UniScript,
  UniDacVcl, SQLServerUniProvider, OracleUniProvider,
  AccessUniProvider, MySQLUniProvider, ODBCUniProvider,
  PostgreSQLUniProvider, InterBaseUniProvider, DBFUniProvider,
  DB2UniProvider, ASEUniProvider, AdvantageUniProvider, MemDS,
  OleServer, dxSkinOffice2010Blue;

type
  TDataM = class(TDataModule)
    cxImagesmall: TcxImageList;
    kpdb: TDatabase;
    dxSkinController1: TdxSkinController;
    cxLocalizer1: TcxLocalizer;
    frxDesigner1: TfrxDesigner;
    frxReport1: TfrxReport;
    sd: TSaveDialog;
    od: TOpenDialog;
    cxImagelarge: TcxImageList;
    UniConnection1: TUniConnection;
    SQLiteUniProvider1: TSQLiteUniProvider;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    UniScript1: TUniScript;
    UniConnectDialog1: TUniConnectDialog;
    SQLServerUniProvider1: TSQLServerUniProvider;
    MySQLUniProvider1: TMySQLUniProvider;
    AccessUniProvider1: TAccessUniProvider;
    OracleUniProvider1: TOracleUniProvider;
    AdvantageUniProvider1: TAdvantageUniProvider;
    ASEUniProvider1: TASEUniProvider;
    DB2UniProvider1: TDB2UniProvider;
    DBFUniProvider1: TDBFUniProvider;
    InterBaseUniProvider1: TInterBaseUniProvider;
    PostgreSQLUniProvider1: TPostgreSQLUniProvider;
    Queryxf: TQuery;
    tempquery: TUniQuery;
    kpdbsuit: TDatabase;
    UniConnection2: TUniConnection;
    UniConnectDialog2: TUniConnectDialog;
    procedure kpdbBeforeConnect(Sender: TObject);
    procedure kpdbsuitBeforeConnect(Sender: TObject);
  private
    { Private declarations }
  public
    constructor Create(AOwner: TComponent);override;
    destructor Destroy;override;
  end;

var
  DataM: TDataM=nil;

implementation
uses ushare, MyConnectForm,gdata;
{$R *.dfm}




constructor TDataM.Create(AOwner: TComponent);
var
  fpath:string;
  kpinfo:Tkpinfo;
begin
inherited;
fpath:=ExtractFilePath(GetModuleName(HInstance));
cxLocalizer1.FileName:=fpath+'chs.ini';
cxLocalizer1.Active:=true;
cxLocalizer1.Locale:=2052;
kpinfo:=getkppath;
if kpinfo.kppath<>'' then
begin
installkp:=True;
if not kpdbsuit.Session.IsAlias('kpworksuit') then
  begin
  kpdbsuit.Session. ConfigMode:=cmSession;
  kpdbsuit.Session.configmode:=cmAll;
  kpdbsuit.Session.AddStandardAlias('kpworksuit',kpinfo.kppath+'\DATABASE\SYSTEM\SUIT','paradox');
  end;
if not kpdb.Session.IsAlias('kpwork') then
  begin
  kpdb.Session. ConfigMode:=cmSession;
  kpdb.Session.configmode:=cmAll;
  kpdb.Session.AddStandardAlias('kpwork',kpinfo.kppath+'\DATABASE\DEFAULT\WORK','paradox');
  end;
  end
  else
  installkp:=False;
   UniConnection1.ProviderName:=loadreginfo(unisetkeypath+'\'+application.Title,'Provider',False);

   if UniConnection1.ProviderName='SQLite' then
       begin
       UniConnection1.SpecificOptions.Values['ClientLibrary']:='sqlite31.dll';
       UniConnection1.SpecificOptions.Values['EncryptionKey']:=ushare.loadreginfo(unisetkeypath+'\'+application.Title,'pw',true);

      end
      else
      UniConnection1.Password:=ushare.loadreginfo(unisetkeypath+'\'+application.Title,'pw',true);
      TUniConnectDialogUtils.ReloadInfoFromRegistry(UniConnectDialog1);
  if UniConnection1.Database<>'' then
     UniConnection1.LoginPrompt:=False
     else
     UniConnection1.LoginPrompt:=true;

end;

destructor TDataM.Destroy;
begin
  UniConnection1.Close;
  if installkp then
  begin
  kpdb.Close;
  kpdb.Session.DeleteAlias('kpwork');
  kpdb.Close;
  kpdb.Session.DeleteAlias('kpworksuit');
  end;
  inherited;

end;
procedure TDataM.kpdbBeforeConnect(Sender: TObject);
begin
kpdb.Session.AddPassword('jIGGAe');
end;
procedure TDataM.kpdbsuitBeforeConnect(Sender: TObject);
begin
kpdbsuit.Session.AddPassword('jIGGAe');
end;
initialization
finalization

end.
